<?php

class UserModel extends Model {

	public $table = '360_user';
	// 用户注册方法
	public function UserReg(){
		// POST来的用户名称
		$Account = $_POST['account'];
		// 从数据库检索数据，有数据说明该用户名一杯注册
		$field = $this->where("account = '{$Account}'")->find();
		if($field){
			$this->error = '用户名已存在';
			return false;
		}
		if(strlen($_POST['account'])>=4){
			if(strlen($_POST['password'])>=6){
				unset($_POST['pwded']);
				$_POST['reg_time'] = time();
				$_POST['password'] = md5($_POST['password']);
				return $this->insert($_POST);
			}else{
				$this->error = '密码长度应该大于6位字符';
				return false;
			}
			
		}else{
			$this->error = '用户名长度应该大于6位字符';
			return false;
		}
	}
	// 用户登录
	public function UserLogin(){
		// 用户名
		$Account = $_POST['account'];
		// 从数据库检索数据，有数据说明该用户名存在
		$Field = $this->where("account = '{$Account}' ")->find();
		// 给POST数据加密
		$Pass = md5($_POST['password']);
		if($Field){
			if($Field['password'] == $Pass){
				$_SESSION['id'] = $Field['uid'];
				$_SESSION['account'] = $Field['account'];
				$Sql = "INSERT INTO 360_user_login_record (uid,login_time,ip) VALUES (".$Field['uid'].','.
					time().','.
					"'{$_SERVER['REMOTE_ADDR']}'".
					")";

				return $this->exe($Sql);
			}else{
				$this->error = '密码错误';
				return false;
			}
		}else{
			$this->error = '用户名错误';
			return false;
		}
	}

}


?>